package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/find-the-minimum-area-to-cover-all-ones-i/?envType=daily-question&envId=2025-08-22
 * @create 2025/8/22 09:00
 * @since JDK17
 */

public class Solution43 {
    public int minimumArea(int[][] grid) {
        int n = grid.length, m = grid[0].length, r1 = n, r2  = 0, c1 = m, c2 = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[i][j] != 0) {
                    r1 = Math.min(r1, i);
                    c1 = Math.min(c1, j);
                    r2 = Math.max(r2, i);
                    c2 = Math.max(c2, j);
                }
            }
        }
        return (r2 - r1 + 1) * (c2 - c1 + 1);
    }
}
